Skip to main content

HTML Form Attributes

This chapter describes the different attributes for the HTML <form> element.

The Action Attribute

When a form is submitted, an action is defined by the action attribute.

When a user clicks the submit button on a form, the form's data is typically transmitted to a file on the server.

The form data in the example below is delivered to a file called "action page.php." A server-side script that manages the form data is contained in this file:

Example

On submit, send form data to "action_page.php":

<form action="/action_page.php">
<label for="fname">First name:</label><br />
<input type="text" id="fname" name="fname" value="John" /><br />
<label for="lname">Last name:</label><br />
<input type="text" id="lname" name="lname" value="Doe" /><br /><br />
<input type="submit" value="Submit" />
</form>
tip

If the action attribute is omitted, the action is set to the current page.

The Target Attribute

The response that is returned after submitting the form is specified by the target attribute.

One of the following values may be present for the target attribute:

ValueDescription
_blankThe response is displayed in a new window or tab
_selfThe response is displayed in the current window
_parentThe response is displayed in the parent frame
_topThe response is displayed in the full body of the window
framenameThe response is displayed in a named iframe

The default value is _self which means that the response will open in the current window.

Example

Here, the submitted result will open in a new browser tab:

<form action="/action_page.php" target="_blank"></form>

The Method Attribute

The HTTP method to utilize when submitting form data is specified by the method property.

Both URL variables (with method="get") and HTTP post transactions (with method="post") may be used to send the form data.

When submitting form data, the default HTTP method is GET.

Example

This example uses the GET method when submitting the form data:

<form action="/action_page.php" method="get"></form>
Example

This example uses the POST method when submitting the form data:

<form action="/action_page.php" method="post"></form>
Notes on GET
  • Appends the form data to the URL, in name/value pairs
  • NEVER send sensitive information via GET! (The URL shows the data from the submitted form!)
  • A URL can only be a certain length (2048 characters)
  • helpful when a user wants to bookmark the outcome after submitting a form.
  • GET is suitable for non-secure data, such as Google query strings.
Notes on POST
  • Appends the form data inside the body of the HTTP request (the submitted form data is not shown in the URL)
  • POST has no file size restrictions and may be used to transfer big data.
  • No bookmarks can be used with POST form submissions.

The Autocomplete Attribute

A form's autocomplete setting may be turned on or off using the autocomplete property.

When autocomplete is enabled, the browser fills in values depending on those that the user has already typed.

Example

A form with autocomplete on:

<form action="/action_page.php" autocomplete="on"></form>